<html>
<head>
<meta charset="UTF-8">
<title>KBEngine - KBEngine logger</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align=left style="background:#708090"> <font size=15 color=#ffffff> KBEngine </font></td></tr>
</table> <hr>
<h1>KBEngine module</h1>
This <a href="KBEngine.html">KBEngine</a> module provides 
Python scripts the ability to control, analyze, and dump certain types 
of logs.


<h2><a href="#" onClick="obj=document.getElementById( 'functions' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Member functions</a></h2>
<table id="functions" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#addTimer" class="function_list" >addTimer</a>( initialOffset, repeatOffset=0, callbackObj=None ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#delTimer" class="function_list" >delTimer</a>( id ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#urlopen" class="function_list" >urlopen</a>( url, callback, postData, headers ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'callbacks' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Callbacks</a></h2>
<table id="callbacks" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#onLoggerAppReady" class="function_list" >onLoggerAppReady</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onLoggerAppShutDown" class="function_list" >onLoggerAppShutDown</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onLogWrote" class="function_list" >onLogWrote</a>( datas ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onReadyForShutDown" class="function_list" >onReadyForShutDown</a>( ):</span>
</td></tr>

</table>


<hr>
<h2>Member functions documentation</h2>

<a name="addTimer"></a><p class="function_definition">
<span class="function_definition">def addTimer( <i>initialOffset, repeatOffset=0, callbackObj=None</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Registers a timer. The timer triggers the callback function callbackObj. 
The callback function will be executed the first time after "initialOffset" 
seconds, and then will be executed once every "repeatOffset" seconds.
<br><br>
Example:

<pre><pre># Here is an example of using addTimer
        import <a href="../Modules/KBEngine.html">KBEngine</a>
&nbsp;
        # Add a timer, perform the first time after 5 seconds, and execute once every 1 second. The user parameter is 9
        KBEngine.addTimer( 5, 1, onTimer_Callbackfun )
&nbsp;
        # Add a timer and execute it after 1 second. The default user parameter is 0.
        KBEngine.addTimer( 1, onTimer_Callbackfun )
&nbsp;
    def onTimer_Callbackfun( id ):
        print "onTimer_Callbackfun called: id %i" % ( id )
        # If this is a repeated timer, it is no longer needed, call the following function to remove: 
        #     KBEngine.delTimer( id )</pre>
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>initialOffset</i></span></td><td><span class="function_parameter_description">
float, specifies the time interval in seconds for the timer to register from the first callback.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>repeatOffset</i></span></td><td><span class="function_parameter_description">
float, specifies the time interval (in seconds) between each execution after  
the first callback execution. You must remove the timer with the function 
<a href="#delTimer">delTimer</a>, otherwise it will continue to repeat. 
Values less than or equal to 0 will be ignored.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callbackObj</i></span></td><td><span class="function_parameter_description">
function, the specified callback function object
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>integer, the internal id of the timer. This id can be used to 
remove the timer from <a href="#delTimer">delTimer</a>.
</td></tr>
</table>
</p>



<a name="delTimer"></a><p class="function_definition">
<span class="function_definition">def delTimer( <i>id</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The delTimer function is used to remove a registered timer. The removed timer is 
no longer executed. Single-shot timers are automatically removed after 
the callback is executed, and it is not necessary to use the delTimer 
function to remove it. If the delTimer function is passed an invalid id 
(for example, timer was removed), it will generate an error.
<br><br>
A use case is shown in the KBEngine.<a href="#addTimer">addTimer</a> example.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>id</i></span></td><td><span class="function_parameter_description">
integer, which specifies the timer id to remove.
</span></td></tr>

</table>
</p>



<a name="urlopen"></a><p class="function_definition">
<span class="function_definition">def urlopen( <i>url, callback, postData, headers</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function is providing an external HTTP/HTTPS asynchronous request.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>url</i></span></td><td><span class="function_parameter_description">
A valid HTTP/HTTPS URL.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td>
<td><p class="function_parameter_description">
Optional parameter with a callback object (for example, a function) that requests execution results. This callback takes five parameters: the HTTP request return code (eg: 200), 
the returned content, the returned HTTP protocol header, whether it succeeded, and the requested URL.
<br>
Example:<br>
def 
onHttpCallback(httpcode, data, headers, success, url):<br>
&nbsp;&nbsp;&nbsp;&nbsp;print(httpcode, data, headers, success, url)  <br>
<br>
As the above example shows:
<br><p class="function_parameter_description"></p>httpcode:The parameter corresponds to the &quot;HTTP request return code&quot;, is an integer.
<p class="function_parameter_description"></p>data:The parameter is &ldquo; returned content & rdquo;, it is a string.
</p>
<p class="function_parameter_description">headers:The parameter is the HTTP protocol header returned by the server, such as:{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
<p class="function_parameter_description">success:Whether the execution is successful or not, when the request execution has an error, it is False, and the error information can be further judged by httpcode.
</p>
<p class="function_parameter_description"></p>url:Is the URL used by the request.
</p>
</td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>postData</i></span></td><td><span class="function_parameter_description">
Optional parameter, the default is GET mode request server. If you need POST mode, please provide the content that needs POST. The engine will automatically request the server using POST, is an bytes.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>headers</i></span></td><td><span class="function_parameter_description">
Optional parameter, HTTP header used when requesting, such as：{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
</span></td></tr>

</table>
</p>

        

<hr>
<h2>Callback functions documentation</h2>

<a name="onLoggerAppReady"></a><p class="function_definition">
<span class="function_definition">def onLoggerAppReady( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when the current process is ready.
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>



<a name="onLoggerAppShutDown"></a><p class="function_definition">
<span class="function_definition">def onLoggerAppShutDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when the process shuts down.
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>



<a name="onLogWrote"></a><p class="function_definition">
<span class="function_definition">def onLogWrote( <i>datas</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
If this function is implemented in the script, it is invoked when the 
logger process obtains a new log.<br><br>
The database interface is defined in <a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->dbmgr->databaseInterfaces.<br>

<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).<br>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>datas</i></span></td><td><span class="function_parameter_description">
bytes, log data.
</span></td></tr>

</table>
</p>



<a name="onReadyForShutDown"></a><p class="function_definition">
<span class="function_definition">def onReadyForShutDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
If this function is implemented in the script, it is called when the 
process is ready to exit.<br><br>

You can use this callback to control when the process exits.<br>
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
bool, if it returns True, it allows the process to exit. Returning other 
values will cause the process to ask again after a period of time.
</td></tr>
</table>
</p>




<hr>
<p class="copyrightFooter">Copyright KBEngine</p>
</body>
</html>
